<template>
  <div class="home">
     <div id="app">
      <div class="header">
        <div class="tou">
          <h1>饿了么</h1>

          <div class="gengduo"><span>...</span> <span>x</span></div>
        </div>

        <div class="sousuo">
         <van-search
                  @click.native="$router.push('/search')"
                  shape="round"
                  background="#4fc08d"
                  placeholder="输入商家信息"
                />
        </div>
      </div>

      
     <Swiper :bannerlist="bannerlist"></Swiper>


      <main>
        <h3>猜你喜欢</h3>

        <div class="paixu">
          <ul>
            <li>综合排序∨</li>

           <li @click="juli">离我最近</li>
      <li @click="sale">销量最高</li>

            <li>筛选</li>
          </ul>
        </div>

        <div class="shaixuan">
          <ul>
            <li>年货节热卖</li>

            <li>津贴联盟</li>

            <li>满减优惠</li>

            <li>品质联盟</li>
          </ul>
        </div>
        </main>

    <div class="list">
      <!-- /detail/12312312312 -->
      <!-- $router.push('/detail/'+item.mtWmPoiId) -->
      <!-- $router.push({name:'detail',params:{id:item.mtWmPoiId} }) -->
      <van-list
  v-model="loading"
  :finished="finished"
  finished-text="到底了"
  @load="onLoad"
>
  <!-- <van-cell v-for="item in list" :key="item" :title="item" /> -->
  <div @click="$router.push({path:'/detail',query:{id:item.mtWmPoiId} })" class="shop" v-for="(item,index) in list" :key="index">
        <div class="img-box">
          <img :src="item.picUrl" alt="">
        </div>
        <div class="text">
          <div>{{item.shopName}}</div>
          <div>{{item.monthSalesTip}}</div>
          <div>{{item.minPriceTip}}</div>
        </div>
      </div>
</van-list>
    
    </div>
    </div>
    <Tabbar></Tabbar>
  </div>
</template>

<script>
import { shop_list ,banner_list} from '../utils/api'

export default {
  name: 'HomeView',
  data(){
    return {
      page:0,
      active:0,
      list:[],
      bannerlist:[],
      loading: false,//控制上啦加载的loading动画的显示/隐藏
      finished: false,//控制上拉加载的所有数据是否加载完，数据已加载完，则显示finished-text文本
    }
  },
  mounted(){
    //发请求, 获取 店铺列表
    // shop_list().then((res)=>{
    //   console.log(res.data);
    //   //保存店铺列表
    //   this.list = res.data.list;
    // })
    banner_list({}).then((res)=>{
      this.bannerlist=res.data.list;
    })
  },
  methods: {
      onLoad() {
        this.loading=true,
        //加载下一页数据
        shop_list({page:this.page+1,count:5}).then((res)=>{
          //将请求到的店铺列表数据和当前列表合并
         this.list= this.list.concat(res.data.list);
         if(res.data.list.length==0){
this.finished=true;
           }
           this.loading=false;
         //页码+1
         this.page++;
        })
      },
    juli() {
      this.list.sort((a, b) => {
        return parseFloat(a.distance) - parseFloat(b.distance);
      });
      // console.log(this.storeList);
    },
    sale() {
      this.list.sort((a, b) => {
        return b.monthSalesTip.slice(2) - a.monthSalesTip.slice(2);
      });
    },
  },
}
</script>

<style lang="scss" scoped>

 

.shop{
  display: flex;
  margin: 10px;
  .img-box{
    width: 100px;
    margin-right: 10px;
    img{
      width: 100%;
    }
  }
  .text{
    flex:1;
  }
}
#app {
  .listt{
    margin-bottom: 3.75rem;
  }
  .header {
    width: 100%;
    background-color: rgb(62, 153, 255);
    color: white;
    .tou {
      display: flex;
      padding-top: 10px;
      padding-left: 20px;
      padding-right: 20px;
      justify-content: space-between;
      h1 {
        font-size: 16px;
      }
      .gengduo {
        display: flex;
        justify-content: space-evenly;
        background-color: rgba(0, 0, 0, 0.173);
        width: 50px;
        border-radius: 10px;
      }
    }
    .sousuo {
      padding: 10px;
      input {
        border: none;
        height: 30px;
        line-height: 30px;
        text-align: center;
        width: 100%;
        border-radius: 20px;
      }
    }
  }
  .banner {
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    img {
      width: 100%;
    }
  }
  main {
    .paixu {
      margin: 5px;
      font-weight: 600;
      ul {
        display: flex;
        justify-content: space-around;
        list-style: none;
      }
    }
    .shaixuan {
      margin: 5px;
      ul {
        display: flex;
        list-style: none;
        justify-content: space-around;
        li {
          height: 30px;
          line-height: 30px;
          font-size: 12px;
          width: 87px;
          text-align: center;
          background-color: #eee;
          border-radius: 5px;
        }
      }
    }}}
</style>
